A routing device, such as a router, typically routes a received packet based upon the packet's destination address, which may be a 32 bit number (displayed as A.B.C.D such as 192.168.2.1) in internet protocol version 4 (IPv4), or a 128 bit number in internet protocol version 6 (IPv6). The routing device is generally configured to use a packet's destination internet protocol (IP) address (which may be stored in the packet's header) to perform a lookup in the device's routing table and then forward the packet based upon the results of the lookup.
An entry in a router's routing table is typically of the form (prefix, forwarding_info), where prefix is an address (such as an IP address) or a prefix representing a range of addresses and forwarding info can indicate the action to be taken on the packet having the corresponding prefix. For example, in IPv4 the prefix may represent an IP address in the form A.B.C.D (e.g., 192.168.2.1). Alternatively, the prefix may also represent a range of addresses such as 103.23.3.0/24, where 24 is the length of the prefix and the last 8 bits are wildcards (this represents a range of 256 addresses from 103.23.3.0 through 103.23.3.255).
A packet's destination address could match multiple routes. For example, destination 192.168.2.1 matches routes 192.0.0.0/8, 192.168.0.0/16 and 192.168.2.0/24. Typically, in such a scenario, the longest match (e.g., 192.168.2.0/24) is selected and corresponding action taken.
The forwarding information associated with a prefix in a routing table entry indicates an action to be taken for a packet whose destination address matches the prefix. The action may for example be related to how the packet is to be forwarded. For example, the forwarding information may indicate a port of the router to which the packet is to be forwarded, the next hop device to which the packet is to be forwarded, and other like information.
Ternary content-addressable memories (TCAMs) are now commonly used for storing routing table information in routers. A TCAM is a special type of fully associative memory capable of storing multiple entries and that allows fully parallel search of its contents. A TCAM is thus well suited for handling IP addresses described above. In other words, a TCAM receives a data word, as an input and uses that data word to return one or more storage addresses where the word can be found. Each entry of a TCAM typically has a prefix entry and an action entry. The input data can be compared with all the TCAM prefix entries in parallel. If there are multiple matches, an action associated with longest matched entry is performed. The “action” can be sending the packet to a particular port, dropping the packet, etc.
To facilitate the parallel matching process, the entries in a TCAM are generally organized to facilitate parallel matching and identification of the longest match. For example, for a routing table, the entries in a TCAM are stored in order of decreasing prefix lengths. As a result of such an arrangement, when there are multiple matches, the first entry among the matched entries (i.e., the lowest numbered matched entry) represents the longest match and is thus selected. However, due to the need for the decreasing prefix length arrangement, making updates to the TCAM becomes a non-trivial process that requires movement of several TCAM entries. For example, adding a new entry to the TCAM (e.g., adding a new prefix to the routing table) requires several TCAM movements to find an empty TCAM entry for storing the new value while still maintaining the decreasing prefix length order of the TCAM. Such movements are very time consuming and lower the throughput of the TCAM. In a router, this can even lead to an interruption in packet switching.
Accordingly, various techniques are presently used to improve the efficiency of TCAM updates. For example, in some techniques TCAM entries are intentionally left unused for receiving new additions. However, this technique can lead to wastage of memory and increase the cost of using a TCAM. For example, some existing TCAM management methods either partition TCAM entries into multiple regions, or require the existence of a contiguous free region to hold all of the free TCAM entries. As such, these existing methods involve many movements of free TCAM entries from region to region to satisfy the ordering restriction. In one such approach, a TCAM is divided into 32 regions or partitions for IPv4, where each region includes used prefix entries of the same length (or many more regions for IPv6) as well as unused entries. A TCAM entry of a specified prefix length must be obtained from a partition with that length.
In this example, if a partition runs out of free TCAM entries, then other TCAM entries are either pushed up or down to obtain a free or unused entry. For example, if partition 16 has no free entry, and the closest free entry is in partition 25, this approach must create a free or unused entry in partition 16 by moving a TCAM entry from 24 to 25, 23 to 24, and so on until 16 to 17 is moved. As is evident, this approach could potentially involve many TCAM entry movements resulting in a lot of time needed for TCAM updates. The problem is further aggravated for IP addresses have more prefixes, such as in IPv6.
Another conventional TCAM management technique used in routing devices assumes that internet routes have a statistical maximum binary tree height of 4. This technique thus divides the TCAM into 4 regions, instead of 32 regions. With this approach the number of movements needed when pushing entries up or down is reduced to a maximum of three. However, this technique assumes that the region in which entry is to be added is known ahead of time in order to put it into the correct region to avoid movements. Also, with this technique, several TCAM movements are needed if the binary tree height changes or any region runs out of space. Another problem with this technique is that it will not work if the maximum height of routes exceeds the predefined number of regions. For example, if an internet site advertises its routing binary tree height of 5 or more, then a 4 region TCAM management approach will not work.
Therefore, efficient TCAM management techniques, which can be used in network devices such as routers and that have minimal, if any, impact on the processing of the network device, are desired.